package org.andy.json;

import java.util.Map;
import java.util.HashMap;

public class CourseMap {

    private Map<String, Course> nodes;
    private Map<String, Map<String, Course>> edges;

    public CourseMap() {
        this.nodes = new HashMap<String, Course>();
        this.edges = new HashMap<String, Map<String, Course>>();
    }

    public void addNode(Course course) {
        this.nodes.put(course.getName(), course);
    }

    public void addEdge(Course source, Course target) {
        if (!this.nodes.containsValue(source)) {
            this.addNode(source);
        }

        if (!this.nodes.containsValue(target)) {
            this.addNode(target);
        }

        if (this.edges.containsKey(source.getName())) {
            this.edges.get(source.getName()).put(target.getName(), target);
        } else {
            this.edges.put(source.getName(), new HashMap<String, Course>());
            this.edges.get(source.getName()).put(target.getName(), target);
        }
    }
}
